package com.ismarkendenis.primegenerator;

import java.util.ArrayList;

public class Generator 
{
	public ArrayList<Integer> generatorsOfPrime(int prime)
	{
		ArrayList<Integer> generators = new ArrayList<Integer>();
		
		for (int posGen = 1; posGen < prime; posGen++)
		{
			boolean generator = true;
			int[] toFill      = new int[prime];
			toFill[0]         = 1;
			
			for(int power = 1; power < prime; power++)
			{
				int modulo     = (int)Math.pow(posGen, power) % prime;
				toFill[modulo] = 1;
			}
			
			for (int i = 0; i < toFill.length; i++)
			{
				if(toFill[i] == 0)
				{
					generator = false;
				}
			}
			
			if (generator)
			{
				generators.add(posGen);
			}
		}
		
		return generators;
	}
	
	public ArrayList<Boolean> verifyGenerators(int prime, ArrayList<Integer> generators)
	{
		ArrayList<Boolean> verified = new ArrayList<Boolean>();
		
		for (int generator : generators) 
		{
			verified.add(prime % generator == 1);
		}
		
		return verified;
	}
}
